import random

import pygame


def main():
    pygame.init()
    screen = pygame.display.set_mode((800, 600), 0, 32)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()

        # 填充为黑色
        screen.fill((255, 255, 255))

        rand_col = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))

        for _ in range(300):
            rand_pos = (random.randint(0, 799), random.randint(0, 599))
            color = screen.get_at(rand_pos)

            # 如果未黑色认为是默认填充颜色， 不进行填充
            if color.r == 255 and color.g == 255 and color.b == 255:
                screen.set_at(rand_pos, rand_col)

        pygame.display.update()


main()
